<template>
  <view>
    <js-error mode="top" ref="jsError" z-index="999"></js-error>
    <view style="padding: 10px; margin: 0; width: 100%; text-align: center">
      <!--  -->
      <image
        src="/static/image/home.jpg"
        style="width: 100%; border-radius: 10px"
        mode="widthFix"
      ></image>
    </view>
    <view style="padding: 0 40rpx; margin: 0; width: 100%;text-align: center; overflow: auto;">
      <view style="display: flex; flex-wrap: wrap">
        <view
          v-for="(menu, index) in menuList"
          @click="navTo(menu.url, menu.code,menu.menuName,menu.taskType)"
          style="
            width: 47%;
            margin: 0 0 30rpx 30rpx;
            background: #fff;
            border-radius: 10px;
            padding: 10px 0;
			text-align: center;
          "
          :style="{
            margin: '0 0 15rpx 15rpx',
          }"
		  v-if="menu.isSHow"
        >
			<image :src="menu.src" style="width: 50px; height: 50px"></image>
			<view class="grid-text text-bold">{{ menu.menuName }}</view>
        </view>
		</view>
      </view>
    </view>
  </view>
</template>

<script>
import config from "@/common/config";
import checkVersion from "@/pages/lq-upgrade/checkVersion.js";
import { mapState } from "vuex";
export default {
  data() {
    return {
      barCode: "",
      focus: false,
      cWhType: "",
      appType: "pad",
      model: {
        cWhCode: "",
        cWhName: "",
      },
      carVenSelectList: [],
      show: false,
      listc: [],
      listx: [],
      listh: [],
      menuList: [
        {
          code: "2",
          isSHow: false,
          src: "/static/image/shangji.png",
          menuName: "扫码上机",
          url: "/pages/mes/shangji/saoma",
        },{
          // code: "1",
          code: config.TASK_BUS_TYPE_CGRK,
          isSHow: false,
          src: "/static/image/baogong.png",
          menuName: "扫码报工",
          url: "/pages/mes/baogong/saoma",
        },
        {
          code: "3",
          isSHow: false,
          src: "/static/image/xiaji.png",
          menuName: "扫码下机",
          url: "/pages/mes/xiaji/saoma",
        },
        {
          // code: "4",
          code: config.TASK_BUS_TYPE_SCRK,
          isSHow: false,
          src: "/static/image/touliao.png",
          menuName: "投料登记",
          url: "/pages/mes/touliao/saoma",
        },
        {
          code: "5",
          isSHow: false,
          src: "/static/image/yichang.png",
          menuName: "异常上报",
          url: "/pages/mes/yichang/saoma",
        },
        {
          code: "6",
          isSHow: false,
          src: "/static/image/gongyi.png",
          menuName: "工艺操作手册",
          url: "/pages/mes/files/saoma",
        },
		{
		  code: "6",
		  isSHow: false,
		  src: "/static/image/zdpg.png",
		  menuName: "扫码派工",
		  url: "/pages/mes/zidong/saoma",
		},
      ],
      id: "",
      titleMenu: false,
    };
  },
  onLoad(e) {
    if (uni.getSystemInfoSync().screenWidth > 768) {
      this.appType = "pad";
    } else {
      this.appType = "phone";
    }
    console.log(uni.getSystemInfoSync().screenWidth, "宽带");
    const params = uni.getStorageSync("param");
    this.loadData();
  },
  onShow() {
    // 判断this.$refs下面是否有listDataPosArea
    if (this.$refs.listDataPosArea) {
      this.$refs.listDataPosArea.show = false;
    }
    this.upgrade();
  },
  computed: {
    ...mapState(["vuex_vague", "vuex_vague4", "vuex_vague5"]),
  },

  methods: {
    //检查版本更新
    upgrade() {
      // #ifdef APP-PLUS
      this.$u.api.upgradeCheck().then((res) => {
        console.log(res, "res");
        let url = res.data.apkUrl
          ? res.data.apkUrl
          : this.vuex_config.xtUrl + res.data.xtUrl;
        if (res.result == "true") {
          checkVersion({
            name: res.data.upTitle, //最新版本名称
            code: res.data.upVersion, //最新版本号
            content: `${res.data.upContent}`, //更新内容
            url, //下载链接
            forceUpdate: true, //是否强制升级
          });
        }
      });
      // #endif
    },
    search() {
      let _that = this;
      uni.scanCode({
        scanType: ["barCode", "qrCode"],
        // onlyFromCamera: true,
        success: function (res) {
          console.log("条码类型：" + res.scanType);
          console.log("条码内容：" + res.result);
          _that.barCode = res.result;
        },
      });
    },
    jump() {
      this.barCode = "";
      // this.show = true;
      console.log(this.show, "show====");
      this.$refs.listDataPosArea.show = true;
    },
    confirm() {
      uni.navigateTo({
        url: "/pages/wms/cacheKst/index",
      });
    },
    // 成品入库
    Over(cWhType, flag = "") {
      this.cWhType = cWhType;

      if (flag == "调出") {
        this.cWhType = "5";
      } else if (flag == "调入") {
        this.cWhType = "6";
      }
      this.model = {
        cWhCode: "",
        cWhName: "",
      };
      if (
        (!this.vuex_cpcrk.cWhCode && this.cWhType == "1") ||
        (!this.vuex_hwtz.cWhCode && this.cWhType == "4") ||
        (!this.vuex_ckdbOut.cWhCode && this.cWhType == "5") ||
        (!this.vuex_ckdbIn.cWhCode && this.cWhType == "6")
      ) {
        this.$u.api.tm
          .getWarehouse({
            cWhCode: "",
            cWhType,
          })
          .then((res) => {
            if (res.statecode == "1") {
              this.carVenSelectList = res.subdata.map((item) => {
                item.name = item.cWhName;
                item.value = item.cWhCode;
                return item;
              });
              this.show = true;
            } else {
              this.$u.toast(res.message);
            }
          });
      } else {
        let obj = {};
        obj.cWhType = this.cWhType;

        if (cWhType == "1") {
          obj = {
            ...obj,
            ...this.vuex_cpcrk,
          };
          uni.navigateTo({
            url: "/pages/tm/index/tmCcprk/list?cWhData=" + JSON.stringify(obj),
          });
        } else if (cWhType == "4") {
          obj = {
            ...obj,
            ...this.vuex_hwtz,
          };
          uni.navigateTo({
            url: "/pages/tm/index/tmHwtz/list?cWhData=" + JSON.stringify(obj),
          });
        } else if (cWhType == "5" && flag == "调出") {
          obj = {
            ...obj,
            ...this.vuex_ckdbOut,
          };
          // 仓库调拨—调出
          uni.navigateTo({
            url:
              "/pages/tm/index/tmCkdb/outList?cWhData=" + JSON.stringify(obj),
          });
        } else if (cWhType == "5" && flag == "调入") {
          obj = {
            ...obj,
            ...this.vuex_ckdbIn,
          };
          // 仓库调拨—调入
          uni.navigateTo({
            url: "/pages/tm/index/tmCkdb/inList?cWhData=" + JSON.stringify(obj),
          });
        }
      }
    },

    navTo(url, code,menuName,taskType) {
      if (code) {
		  if(menuName=='缓存区'){
			  this.jump()
		  }else{
			  // jump
			  if(taskType){
				  uni.navigateTo({
				  url: url + "?code=" + code + '&taskType=' + taskType,
				  			  });
			  }else{
				  uni.navigateTo({
				  url: url + "?code=" + code,
				  			  });
			  }
		  }
      } else {
        uni.navigateTo({
          url: url,
        });
      }
    },

    showModal(e) {
      this.modalName = e.currentTarget.dataset.target;
    },
    hideModal(e) {
      this.modalName = null;
    },
    Gridchange(e) {
      this.gridCol = e.detail.value;
    },
    Gridswitch(e) {
      this.gridBorder = e.detail.value;
    },
    MenuBorder(e) {
      this.menuBorder = e.detail.value;
    },
    MenuArrow(e) {
      this.menuArrow = e.detail.value;
    },
    MenuCard(e) {
      this.menuCard = e.detail.value;
    },
    SwitchSex(e) {
      this.skin = e.detail.value;
    },

    // ListTouch触摸开始
    ListTouchStart(e) {
      this.listTouchStart = e.touches[0].pageX;
    },

    // ListTouch计算方向
    ListTouchMove(e) {
      this.listTouchDirection =
        e.touches[0].pageX - this.listTouchStart > 0 ? "right" : "left";
    },
    /**
     * 请求静态数据只是为了代码不那么乱
     * 分次请求未作整合
     */
    async loadData() {
      var _this = this;
      this.$u.api.menuTree().then((res) => {
        if (res.length > 0) {
          res.forEach((item) => {
            if ("权限管理" == item.menuName) {
              item.childList.forEach((item2) => {
				  console.log(item2.menuName,'item2.menuName===')
                if ("MES-APP权限" == item2.menuName) {
                  this.showMenu(item2.childList);
                }
              });
            }
          });
        }
      });
    },

    //显示菜单
    showMenu(list) {
      this.menuList.forEach((item) => {
        list.forEach((res) => {
          if (res.menuName == item.menuName) {
            item.isSHow = true;
            return;
          }
        });
      });

    },

    // ListTouch计算滚动
    ListTouchEnd(e) {
      if (this.listTouchDirection == "left") {
        this.modalName = e.currentTarget.dataset.target;
      } else {
        this.modalName = null;
      }
      this.listTouchDirection = null;
    },
    navToDetailUrl(char) {},
  },
};
</script>

<style lang="scss">
.slot-content {
  padding: 100rpx 32rpx;

  .slot-content-view {
    margin-top: 20rpx;
    line-height: 60rpx;
  }
}
/deep/ uni-page-wrapper{
	background: #f1f1f1 important !important;
}

/* #ifdef MP */
page {
  .cate-section {
    position: relative;
    z-index: 5;
    border-radius: 16upx 16upx 0 0;
    margin-top: -20upx;
  }

  .carousel-section {
    padding: 0;

    .titleNview-placing {
      padding-top: 0;
      height: 0;
    }

    .carousel {
      .carousel-item {
        padding: 0;
      }
    }

    .swiper-dots {
      left: 45upx;
      bottom: 40upx;
    }
  }

  text {
    font-size: 60upx;
  }
}


/* #endif */
// page {
//   background: #ffffff;
// }
</style>